﻿using Microsoft.EntityFrameworkCore;
using PesticideManage.API.Services.Identity.RoleAggregate;
using PesticideManage.API.Services.Identity.UserAggregate;
using PesticideManage.API.Services.Menus;
using PesticideManage.Domain.AggregatesModel.BatchQRCodeAggregate;
using PesticideManage.Domain.AggregatesModel.PesticideAggregate;
using Shang.Microservice.Domain.Abstructions.SeedWork;

namespace PesticideManage.API.Data;

public class PesticideContext : DbContext, IUnitOfWork
{
    public PesticideContext(DbContextOptions<PesticideContext> options) : base(options)
    {
        // No need for change tracking.
        // ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
    }
    public DbSet<User> Users { get; set; } = null!;
    public DbSet<Pesticide> Pesticides { get; set; } = null!;
    public DbSet<BatchQRCode> BatchQRCodes { get; set; } = null!;
    public DbSet<InvalidQRCode> InvalidQRCodes { get; set; }
    public DbSet<Role> Roles { get; set; } = null!;
    public DbSet<ID> IdentityCards { get; set; } = null!;
    public DbSet<Menu> Menus { get; set; } = null!;

    public Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default)
    {
        throw new NotImplementedException();
    }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Role>()
            .Navigation(r => r.Menus).AutoInclude();
    }
}
